﻿using System;
using System.Collections.Generic;

namespace Top.Api.Sync
{
    public sealed class DateTimeUtils
    {
        public static DateTime ParseDateTime(string str)
        {
            return DateTime.ParseExact(str, "yyyy-MM-dd HH:mm:ss", null);
        }

        public static DateTime GetTodayStartTime()
        {
            return DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd"), "yyyy-MM-dd", null);
        }

        public static List<DateTime[]> SplitTimeByDays(DateTime start, DateTime end, int days)
        {
            List<DateTime[]> dl = new List<DateTime[]>();
            while (start.CompareTo(end) < 0)
            {
                DateTime _end = start.AddDays(days);
                if (_end.CompareTo(end) > 0)
                {
                    _end = end;
                }
                DateTime[] dates = new DateTime[] { start, _end };
                dl.Add(dates);
                start = _end;
            }
            return dl;
        }
    }
}
